<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Description of array_library
 *
 * @author daniel
 */
class Array_library {

	function remove_matching_keys($array, $needle) {
		if (empty($array) || empty($needle)) {
			return FALSE;
		}

		$new_array = array();

		foreach ($array as $key => $value) {
			$found = strstr($key, $needle);

			if (!$found) {
				$new_array[$key] = $value;
			}
		}

		return $new_array;
	}

	function preserve_matching_keys($array, $needle) {
		$new_array = array();

		foreach ($array as $key => $value) {
			if (strstr($key, $needle)) {
				$new_array[$key] = $value;
			}
		}

		return $new_array;
	}

	function replace_in_keys($array, $str) {
		$new_array = array();

		foreach ($array as $key => $value) {
			$first_index = strpos($key, $str);

			if ($first_index !== FALSE) {
				$key = substr_replace($key, '', $first_index, strlen($str));
			}

			$new_array[$key] = $value;
		}

		return $new_array;
	}

}
?>
